/**
 * 开关
 */
Switchcraft = Widget.extend({
	ctor:function(parent){
		this._super();
		parent.addChild(this,30);
		this.init();
		this.setTag(TAG_SWITCHCRAFT);
	},
	init:function(){
		this.setCascadeOpacityEnabled(true);

		// 开关
		var switchcraft_body = new Button(this, 10, TAG_SWITCHCRAFT_BODY, "#switch1.png", this.callback);
		switchcraft_body.setPosition(cc.p(640,160));
		//  开关闸
		var switchcraft_part = new Button(switchcraft_body, 10, TAG_SWITCHCRAFT_PART, "#switch2.png", this.callback);
		switchcraft_part.setPosition(cc.p(69,69));
		switchcraft_part.setAnchorPoint(0.1, 0.1);
		
		this.callNext = cc.callFunc(function(){
			gg.flow.next();
		}, this);
		this.callNext.retain();
	},
	callback:function (p){
		var action=gg.flow.flow.action;
		switch(p.getTag()){
		case TAG_SWITCHCRAFT_PART:		
			if(action==ACTION_DO1){
				var rot = cc.rotateBy(0.8,52);
				var seq = cc.sequence(rot,cc.callFunc(function() {
					var finger = ll.run.getChildByTag(TAG_AMMETER).getChildByTag(TAG_AMMETER_BODY).getChildByTag(TAG_AMMETER_FINGER);
					var rot1 = cc.rotateBy(0.5, 20);
					var rot2 = cc.rotateBy(0.5, -15);
					var rot3 = cc.rotateBy(0.5, 5);
					var seq1 = cc.sequence(rot1,rot2,rot3);
					finger.runAction(seq1);
				}, this),cc.delayTime(1.8),cc.callFunc(function() {
					gg.flow.next();
				}, this));
				p.runAction(seq);
			}else if(action==ACTION_DO2){
				var rot = cc.rotateBy(0.8,-52);
				var seq = cc.sequence(cc.callFunc(function() {
					var finger = ll.run.getChildByTag(TAG_AMMETER).getChildByTag(TAG_AMMETER_BODY).getChildByTag(TAG_AMMETER_FINGER);
					var rot1 = cc.rotateBy(1, -35);
					finger.runAction(rot1);
					var kerosene1 = ll.run.getChildByTag(TAG_FLASK).getChildByTag(TAG_FLASK1).getChildByTag(TAG_KEROSENE1);
					var kerosene2 = ll.run.getChildByTag(TAG_FLASK).getChildByTag(TAG_FLASK2).getChildByTag(TAG_KEROSENE2);
					kerosene1.runAction(cc.scaleTo(3, 1, 1));
					kerosene2.runAction(cc.scaleTo(3, 1, 1));					
				}, this),rot,cc.delayTime(3.5),cc.callFunc(function() {
					gg.flow.next();
				}, this));
				p.runAction(seq);
			}else if(action==ACTION_DO3){
				var rot = cc.rotateBy(0.8,52);
				var seq = cc.sequence(rot,cc.callFunc(function() {
					var finger = ll.run.getChildByTag(TAG_AMMETER).getChildByTag(TAG_AMMETER_BODY).getChildByTag(TAG_AMMETER_FINGER);
					var rot1 = cc.rotateBy(0.5, 38);
					var rot2 = cc.rotateBy(0.5, -6);
					var rot3 = cc.rotateBy(0.5, 3);
					var seq1 = cc.sequence(rot1,rot2,rot3);
					finger.runAction(seq1);
				}, this),cc.delayTime(1.8),cc.callFunc(function() {
					gg.flow.next();
				}, this));
				p.runAction(seq);
			}else if(action==ACTION_DO4){
				var rot = cc.rotateBy(0.8,-52);
				var seq = cc.sequence(cc.callFunc(function() {
					var finger = ll.run.getChildByTag(TAG_AMMETER).getChildByTag(TAG_AMMETER_BODY).getChildByTag(TAG_AMMETER_FINGER);
					var rot1 = cc.rotateBy(1, -71);
					finger.runAction(rot1);
//					var kerosene1 = ll.run.getChildByTag(TAG_FLASK).getChildByTag(TAG_FLASK1).getChildByTag(TAG_KEROSENE1);
//					var kerosene2 = ll.run.getChildByTag(TAG_FLASK).getChildByTag(TAG_FLASK2).getChildByTag(TAG_KEROSENE2);
//					kerosene1.runAction(cc.scaleTo(3, 1, 1));
//					kerosene2.runAction(cc.scaleTo(3, 1, 1));					
				}, this),rot,cc.delayTime(3.5),cc.callFunc(function() {
					gg.flow.next();
				}, this));
				p.runAction(seq);
			}
			break;
		default:
			break;
		}
	},
	onExit:function(){
		this._super();
		this.callNext.release();
	}
})